package com.szy.system.servlet.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

/**
 * @author : zhenyun.su
 * @comment : spring容器刷新(启动)后触发事件
 * 功能说明:
 * 1. 可用于在容器启动成功后，初始化数据
 * 2. 另外 spring 提供很多关于容器生命周期时事件
 * 使用说明:
 * 1. 实现接口SystemInitialize，并注入到 SzyContextRefreshedListener
 * 2. 将SzyContextRefreshedListener注册为Bean
 * 来源于： 1-core -> com.szy.event.listener.SzyContextRefreshedListener
 * @since : 2020/3/25
 */

@Deprecated
public class SzyContextRefreshedListener implements ApplicationListener<ContextRefreshedEvent> {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    private ContextReload contextReload;
    public SzyContextRefreshedListener(ContextReload contextReload) {
        this.contextReload = contextReload;
    }

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        logger.info("asu, trigger ContextRefreshedEvent. Can be used for reload config");
        //初始化数据
        contextReload.reload();;
    }
}
